package cn.bestick.cblog.service.impl;

import java.util.List;
import cn.bestick.cblog.dao.CategoryDao;
import cn.bestick.cblog.dao.impl.CategoryDaoImpl;
import cn.bestick.cblog.dmo.Category;
import cn.bestick.cblog.dto.CategoryDto;
import cn.bestick.cblog.service.CategoryService;

public class CategoryServiceImpl implements CategoryService {
	private CategoryDao dao = null;

	public CategoryServiceImpl() {
		this.dao = new CategoryDaoImpl();
	}

	@Override
	public List<CategoryDto> getCategories() {
		List<CategoryDto> results = null;
		try {
			 results = this.dao.all();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

	@Override
	public void updateCategory(Category category) {
		try {
			this.dao.update(category);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void saveCategory(Category category) {
		try {
			this.dao.save(category);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void deleteCategory(Integer id) {
		try {
			this.dao.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public Category getCategory(int categoryId) {
		Category result = null;
		try {
			result = this.dao.get(categoryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public boolean exist(int categoryId) {
		boolean result = false;
		try {
			result = this.dao.exist(categoryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
